import { alovaInstance } from '..'
import type { MenuTree } from '../globals'

// 返回 一个对象或空对象{}
type EmptyBody = Record<PropertyKey, never>
type addMenuType = Omit<MenuTree, 'id' | 'children'>

// 添加菜单
export const addMenu = (data: addMenuType) =>
  alovaInstance.Post<MenuTree>('/system_manage/menu/add_menu', data)

// 删除菜单
export const deleteMenu = (id: number) =>
  alovaInstance.Delete<EmptyBody>('/system_manage/menu/delete_menu/' + id)

// 更新菜单
export const updateMenu = (id: number, data: Partial<addMenuType>) =>
  alovaInstance.Put<MenuTree>('/system_manage/menu/update_menu/' + id, data)

// 菜单列表
export const getMenuTree = () => alovaInstance.Get<MenuTree[]>('/system_manage/menu/get_menu_tree')
